#pragma once

#include <string>
#include <memory>
#include <functional>
#include "mongoose.h"

using namespace std;

class IWebsocketServerCb
{
public:
    IWebsocketServerCb() {}
    virtual ~IWebsocketServerCb() {}
    virtual void onWsServerReceiveMsg(mg_connection *wsConnection, shared_ptr<string> receiveMsg) = 0;
    virtual void onWsServerConnect(mg_connection *wsConnection) = 0;
    virtual void onWsServerClosed(mg_connection *wsConnection) = 0;
    virtual bool checkIfValidWs(mg_connection *, mg_http_message *) {return true;}
};

class IWebsocketServer
{
public:
    IWebsocketServer(mg_mgr *mgr = nullptr){}
    virtual ~IWebsocketServer() {}
    virtual bool startWsServer(int port) = 0;
    virtual bool startWssServer(int port, string certPath, string keyPath) = 0;
    virtual void setListener(IWebsocketServerCb *listener) = 0;
    virtual bool sendMsg(mg_connection *wsConnection, const string &msg) = 0;
    virtual bool disconnect(mg_connection *wsConnection) = 0;
    virtual bool stop() = 0;
    virtual bool run() = 0;
};

